//
//  MySearchBar.m
//  JHZWeiBo
//
//  Created by 张德培 on 16/5/27.
//  Copyright © 2016年 蒋晨成. All rights reserved.
//

#import "MySearchBar.h"

@implementation MySearchBar

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        UIView *bgView = [[UIView alloc]initWithFrame:frame];
        bgView.backgroundColor = [UIColor grayColor];
        [self addSubview:bgView];
        
        self.searchTF = [[UITextField alloc]initWithFrame:CGRectMake(5, 5, kWidth - 10,frame.size.height - 10)];
        self.searchTF.delegate = self;
        self.searchTF.backgroundColor = [UIColor whiteColor];
        self.searchTF.placeholder = @"搜索联系人和群";
        self.searchTF.layer.cornerRadius = 5;
        self.searchTF.leftViewMode = UITextFieldViewModeAlways;
        
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 40, 30)];
        UIImageView *imageview = [[UIImageView alloc]initWithFrame:CGRectMake(10, 0, 30, 30)];
        imageview.image = [UIImage imageNamed:@"search"];
        [view addSubview:imageview];
        self.searchTF.leftView = view;
        
        
        [self addSubview:_searchTF];
    }
    return self;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField isFirstResponder];
    return YES;
}
@end
